﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Model;
using DAL;

public partial class Student_Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //StudentShowList.SelectedIndex = Eval("sex").Equals("男")?0:1;
        //StudentShowList.SelectedValue="<%# DataBinder.Eval(Container.DataItem,'sex')%>";

        string id = Request.QueryString["id"];
        if (id == null || id.Trim().Equals(""))
        {
            msg.Text = "没有相关的数据";
            msg.Visible = true;
            btnSubmit.Visible = false;
            
            StudentShowList.Visible = false;

        }
        else
        {
            id = id.ToUpper();
            SqlDataSource1.SelectCommand = "SELECT * FROM [t_student] where id = '" + id + "'";
        }

        // Label myLabel = (Label)StudentShowList.FindControl("idLabel");
        // msg.Text = myLabel.Text;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Student student = new Student();
        student.Id = ((Label)StudentShowList.Items[0].FindControl("idLabel")).Text;
        student.ClassIn = ((TextBox)StudentShowList.Items[0].FindControl("classInLabel")).Text;
        student.Sex = ((DropDownList)StudentShowList.Items[0].FindControl("sexlist")).SelectedItem.Value;
        student.Age = Int16.Parse(((TextBox)StudentShowList.Items[0].FindControl("ageLabel")).Text);
        student.Email = ((TextBox)StudentShowList.Items[0].FindControl("emailLabel")).Text;
        student.Phone = ((TextBox)StudentShowList.Items[0].FindControl("phoneLabel")).Text;

        StudentManager studentManager = new StudentManager();
        msg.Text = student.Id + " " + student.ClassIn + " " + student.Sex + " " + student.Age + " " + student.Email + " " + student.Phone;
        if (studentManager.updateInfo(student))
        {
            msg.Text="更新成功！";
        }
        else
        {
            msg.Text = "更新失败！";
        }
    }
}
